package com.cqc.googleplay.utils;

import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.StateListDrawable;

public class DrawableUtil {

	/**
	 * 动态创建shape
	 * 
	 * @param rgb
	 * @param radius
	 * @return
	 */
	public static GradientDrawable getDrawable(int rgb, float radius) {
		GradientDrawable drawable = new GradientDrawable();
		drawable.setShape(GradientDrawable.RECTANGLE);// 矩形
		drawable.setCornerRadius(radius);// 4个角的角度
		drawable.setColor(rgb);// 设置填充图片的颜色
		return drawable;
	}

	/**
	 * 动态生成selector
	 * @param pressed
	 * @param normal
	 * @return
	 */
	public static StateListDrawable getSelector(Drawable pressed, Drawable normal) {
		StateListDrawable drawable = new StateListDrawable();
		drawable.addState(new int[] { android.R.attr.state_pressed }, pressed);//按下对应的drawable
		drawable.addState(new int[] {}, normal);//默认的drawable
		return drawable;
	}
}
